#include "stdafx.h"
#include "pgl/mfc/PGLCustomEvent.h"


CPGLCustomEvent::CPGLCustomEvent()
{
}


CPGLCustomEvent::~CPGLCustomEvent()
{
}
void CPGLCustomEvent::Refresh()
{
	CPGLDialog* parent=(CPGLDialog*)GetParent();
	using namespace gfxinterface;
	CGDIpInterface gfx=parent->GetGfxInterface();
	GetRegion().get()->RefreshView(gfx,true);
	parent->SetDirty();
}
CPGLDialog* CPGLCustomEvent::GetPGLDialog()
{
	return (CPGLDialog*)GetParent();
}
void CPGLCustomEvent::GetCoordPoint(CPoint point,double& x,double& y)
{
	CRect rectFull;
	CPGLDialog* parent=GetPGLDialog();
	CGDIpInterface gfx=GetParentGfxInterface();
	parent->GetClientRect(&rectFull);
	CClientDC dc(GetParent());
	Graphics g(dc);
	gfx.SetGraphics(&g);
	gfx.BeginPaint(dc);
	CPGLRegion* pRegion=GetRegion().get();
	pRegion->PushWorldClipBBox(gfx);
	x=gfx.BBToWorldx(point.x);
	y=gfx.BBToWorldy(rectFull.Height()-parent->GetToolBarHeight()-point.y);
	pRegion->PopWorldClipBBox(gfx);
	gfx.EndPaint();
}
void CPGLCustomEvent::GetWorldStep(double& stepX,double& stepY,int pixel)
{
	RECT rect;
	CPGLDialog* parent=GetPGLDialog();
	CGDIpInterface gfx=GetParentGfxInterface();
	parent->GetClientRect(&rect);
	double ww=gfx.GetWorldWidth();
	double cw=rect.right;
	double wh=gfx.GetWorldHeight();
	double ch=rect.bottom-parent->GetToolBarHeight();
	stepX=ww/cw*pixel;
	stepY=wh/ch*pixel;
}